<template lang="html">
  <div>{{text}}</div>
</template>

<script>
export default {
  data() {
    return {
      text: ""
    }
  },
  methods: {
    // 渲染模板
    render (tpl, data) {
      return tpl.replace(/\{\{(\w+)\}\}/g, function (w, c) {
        return data[c]
      })
      // console.log(123);
    },
    test () {
      this.text = this.render('我是{{name}}, 年龄{{age}}, 性别{{sex}}', {name: 'defore', age: 18})
    }
  },
  mounted () {
    this.test();
  }
}
</script>

<style lang="scss" scoped>
</style>
